home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TESTSPAR / COOKIE.S < prev    next >
Encoding:
Text File  |  2001-02-09  |  2.1 KB  |  76 lines

  1. ;+
  2. ; Cookie.s contains routines that deal with the cookie jar which is put in
  3. ; ROM starting with TOS 1.6 (TOS for the STE)
  4. ;
  5. ; 07-Sep-1989    ml.    Started this.
  6. ;-
  7.  
  8. include    "sysvar.h"
  9.  
  10. ;+
  11. ; Getcookie() - To find a cookie and its value
  12. ;
  13. ; int getcookie(cookie, p_value)
  14. ; LONG    cookie;        4(sp).l
  15. ; LONG    *p_value;    8(sp).l
  16. ;
  17. ; Returns:
  18. ;        0: if cookie is NOT found in the cookie jar.
  19. ;    non-0: if cookie is found, and places its value in the
  20. ;        longword pointed to by p_value.
  21. ;
  22. ; Comments:
  23. ;    If p_value is NULL, the value won't be put anywhere, but still
  24. ; returns a return code.
  25. ;
  26. ; Trashes: d0, d1, a0, a1
  27. ;-
  28.     .globl    _getcookie
  29. _getcookie:
  30.     move.l    d3,-(sp)    ; save d3
  31.     clr.l    oldssp        ; assume already in Super mode
  32.     move.l    #1,-(sp)    ; Super(1L)
  33.     move.w    #$20,-(sp)
  34.     trap    #1
  35.     addq.w    #6,sp        ; clean up stack
  36.     tst.w    d0        ; in Super mode already?
  37.     bne.s    .0        ; if so, fine
  38.     clr.l    -(sp)        ; else go to Super mode
  39.     move.w    #$20,-(sp)    ; Super(0L)
  40.     trap    #1
  41.     addq.w    #6,sp        ; clean up stack
  42.     move.l    d0,oldssp    ; save original stack pointer
  43.  
  44. .0:    moveq    #0,d3        ; assume there is no cookie jar
  45.     tst.l    _p_cookie    ; does cookie jar exist?
  46.     beq.s    .3        ; if cookie jar does not exist, return error
  47.     
  48.     move.l    8(sp),d0    ; d0 = target cookie
  49.     move.l    _p_cookie,a0    ; a0 = addr of beginning of cookie jar
  50. .1:    move.l    (a0),d1        ; d1 = next cookie in the cookie jar
  51.     beq.s    .3        ; if no more cookie, return
  52.     cmp.l    d1,d0        ; else is it the cookie that we want?
  53.     beq.s    .2        ; if so, ==> cookie found
  54.     addq.w    #8,a0        ; a0 = address of next cookie
  55.     bra.s    .1
  56.  
  57. .2:    moveq    #1,d3        ; cookie found
  58.     tst.l    $c(sp)        ; p_value == NULL?
  59.     beq.s    .3        ; if so, don't return cookie value
  60.     movea.l    $c(sp),a1    ; a1 -> cookie value
  61.     move.l    4(a0),(a1)    ; return cookie value also
  62.     
  63. .3:    tst.l    oldssp        ; need to go back to user mode?
  64.     beq.s    getcend        ; if not, return
  65.     move.l    oldssp,-(sp)    ; else go back to user mode
  66.     move.w    #$20,-(sp)    ; Super(oldssp)
  67.     trap    #1
  68.     addq.w    #6,sp        ; clean up stack
  69. getcend:
  70.     move.l    d3,d0        ; return with appropiate return code
  71.     move.l    (sp)+,d3    ; restore d3
  72.     rts
  73.  
  74. oldssp:    dc.l    0
  75.  
  76.